package com.wc.算法基础课.A第一讲基础算法.递归.分形之城;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/3/13 15:41
 * @description https://www.acwing.com/problem/content/100/
 */
public class Main {
    static long N, A, B;
    static int t;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        t = sc.nextInt();
        while (t-- > 0) {
            N = sc.nextInt();
            A = sc.nextLong();
            B = sc.nextLong();
            long[] A1 = get(N, A - 1);
            long[] B1 = get(N, B - 1);
            long dx = A1[0] - B1[0];
            long dy = A1[1] - B1[1];
            System.out.printf("%.0f\n", Math.sqrt(dx * dx + dy * dy) * 10);
        }
    }

    static long[] get(long n, long a) {
        if (n == 0) return new long[]{0, 0};
        // block 表示一块的数量， len 表示这个块的边长
        long block = 1L << 2 * (n - 1), len = 1L << n - 1;

        // a % block 表示还剩余多少
        long[] pos = get(n - 1, a % block);
        long x = pos[0], y = pos[1];
        // z表示在第几块内部
        long z = a / block;
        // 旋转90度，水平翻转
        if (z == 0) return new long[]{y, x};
        // 直接平移len
        if (z == 1) return new long[]{x, y + len};
        // 斜着平移len,len
        if (z == 2) return new long[]{x + len, y + len};
        // 逆时针旋转90度，平移
        return new long[]{2 * len - 1 - y, len - 1 - x};
    }
}
